package transport.netty.client;

import entity.RpcResponse;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;


//自定义业务处理
public class NettyClientHandler extends SimpleChannelInboundHandler<RpcResponse> {

    private UnprocessedRequests unprocessedRequests = new UnprocessedRequests();

    //从这里接收返回结果
    @Override
    protected void channelRead0(ChannelHandlerContext chx, RpcResponse rpcResponse) throws Exception {
        if(rpcResponse != null){
            unprocessedRequests.complete(rpcResponse.getRequestId(),rpcResponse);
        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {

    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {

    }
}
